package model.searchers;

import java.io.IOException;
import java.util.ArrayList;

import model.searchers.advancedSearchers.hashTableSearchers.DynamicHashTableSearcher;
import model.searchers.advancedSearchers.hashTableSearchers.StaticHashTableSearcher;
import model.searchers.advancedSearchers.nestedLinkedListSearcher.NestedLinkedListSearcher;
import model.searchers.linkedListSearcher.LinkedListSearcher;

/**
 * This class has the purpose of creating and returning a searcher object
 *
 */

public class SearcherFactory {

	/**
	 *  Create a searcher object
	 *  
	 * @param dataFile			file to search in
	 * @param searcherType		searcher type to create instance of
	 * @param mode				boolean search mode
	 * @param ranking			page ranking mode
	 * @return 					a searcher object of specified type and modes
	 */
	public static ISearcher createSearcher(String dataFile,	String searcherType, boolean mode, boolean ranking) {
		ISearcher searcher = null;

		ArrayList<String> searcherNames = new ArrayList<String>();
		searcherNames.add("LinkedListSearcher");
		searcherNames.add("NestedLinkedListSearcher");
		searcherNames.add("StaticHashTableSearcher");
		searcherNames.add("DynamicHashTableSearcher");
		int operator = searcherNames.indexOf(searcherType);

		try {
			switch (operator) {
			case 0:
				searcher = new LinkedListSearcher(dataFile, mode);				
				break;
			case 1:
				searcher = new NestedLinkedListSearcher(dataFile, mode, ranking);
				break;
			case 2:
				searcher = new StaticHashTableSearcher(dataFile, 128000, mode, ranking);
				break;
			case 3:
				searcher = new DynamicHashTableSearcher(dataFile, 1, mode, ranking);
				break;
			default:
				System.out.println("You need to enter valid arguments!");
				System.out.println("\nEnter the searcher type you wish to use. You can choose between:");
				// Prints out a list of valid searchers
				for (int i = 0; i < searcherNames.size(); i++) {
					System.out.println(searcherNames.get(i));
				}
				System.exit(0);
			}
		} catch (IOException e) {
			System.out.println("The program could not read the data file properly.");				
			e.printStackTrace();
			System.exit(0);
		}
		return searcher;
	}

}
